/* $Id: javascript.js,v 1.2 2006/05/02 18:02:09 diegor Exp $ */

function refresh_date () {
  now = new Date();
  document.getElementById("datetime").innerHTML = now.toLocaleString();
}
function selectAll(box) {
     for(var i=0; i<box.length; i++) {
     box[i].selected = true;
     }
}

function move(fbox, tbox) {
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
          arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();
     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}

function addIt2(selectList,pickList){
  var c = selectList.length	
  for(x=-1; x < c; x++){
	addIt(selectList,pickList)
  }
}
function delIt2(selectList,pickList){
  var c = pickList.length	
  for(x=-1; x < c; x++){
	delIt(selectList,pickList)
  }
}

function addIt(selectList, pickList) {
  var selectIndex = selectList.selectedIndex;
  var selectOptions = selectList.options;
  var pickOptions = pickList.options;
  var pickOLength = pickOptions.length;
  if (selectIndex > -1) {
    pickOptions[pickOLength] = new Option(selectList[selectIndex].text);
    pickOptions[pickOLength].value = selectList[selectIndex].value;
    selectOptions[selectIndex] = null;
    var tempText;
    var tempValue;
    while (pickOLength > 0 && pickOptions[pickOLength].text < pickOptions[pickOLength-1].text) {
      tempText = pickOptions[pickOLength-1].text;
      tempValue = pickOptions[pickOLength-1].value;
      pickOptions[pickOLength-1].text = pickOptions[pickOLength].text;
      pickOptions[pickOLength-1].value = pickOptions[pickOLength].value;
      pickOptions[pickOLength].text = tempText;
      pickOptions[pickOLength].value = tempValue;
      pickOLength = pickOLength - 1;
    }
  }
}

function delIt(selectList, pickList) {
  var selectOptions = selectList.options;
  var selectOLength = selectOptions.length;
  var pickIndex = pickList.selectedIndex;
  var pickOptions = pickList.options;
  if (pickIndex > -1) {
    selectOptions[selectOLength] = new Option(pickList[pickIndex].text);
    selectOptions[selectOLength].value = pickList[pickIndex].value;
    pickOptions[pickIndex] = null;
    var tempText;
    var tempValue;
    while (selectOLength > 0 && selectOptions[selectOLength].text < selectOptions[selectOLength-1].text) {
      tempText = selectOptions[selectOLength-1].text;
      tempValue = selectOptions[selectOLength-1].value;
      selectOptions[selectOLength-1].text = selectOptions[selectOLength].text;
      selectOptions[selectOLength-1].value = selectOptions[selectOLength].value;
      selectOptions[selectOLength].text = tempText;
      selectOptions[selectOLength].value = tempValue;
      selectOLength = selectOLength - 1;
    }
  }
}

function getIt(list)
{
  var pickList = list;
  var s = '';
  for (var i = 0; i < pickList.length; i++) {
    if (s != '') {
      s += ',';
    }
    s += pickList[i].value;
  }
  return s;
}

function byID(id) 
{
    return document.getElementById(id)
}
